//
//  ZJShareManager.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/15.
//  Copyright © 2017年 刘应平. All rights reserved.
//

//分享界面

#import "ZJShareManager.h"
#import <UMSocialCore/UMSocialCore.h>
@implementation ZJShareManager

- (instancetype)init
{
    self = [super init];
    if (self) {
        ZYShareItem *item0 = [ZYShareItem itemWithTitle:@"微信朋友圈" icon:@"icon_pengyouquan" handler:^{
            [self shareWebPageToPlatform1111Type:UMSocialPlatformType_WechatTimeLine];
        }];
        ZYShareItem *item1 = [ZYShareItem itemWithTitle:@"微信好友"
                                                   icon:@"icpn_weixin"
                                                handler:^{
                                                    
        [self shareWebPageToPlatform1111Type:UMSocialPlatformType_WechatSession];
                                                }];
        
        ZYShareItem *item2 = [ZYShareItem itemWithTitle:@"手机QQ"
                                                   icon:@"icon_qq"
                                                handler:^{
                                                    
        [self shareWebPageToPlatform1111Type:UMSocialPlatformType_QQ];
                                                }];
        ZYShareItem *item3 = [ZYShareItem itemWithTitle:@"QQ空间"
                                                   icon:@"icon_kongjian"
                                                handler:^{
         [self shareWebPageToPlatform1111Type:UMSocialPlatformType_Qzone];
                                                }];
        NSMutableArray *shareItemsArray = [NSMutableArray arrayWithObjects:item0, item1, item2, item3, nil];
        
        self.shareView = [[ZYShareView alloc] initWithItemsArray:@[shareItemsArray]];

        
    }
    return self;
}

- (void)show{
    [self.shareView show];
}

- (void)shareWebPageToPlatform1111Type:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    NSString *title = self.shareModel.title ? self.shareModel.title : @"";
    NSString *descr = self.shareModel.descr ? self.shareModel.descr : @"";
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:descr thumImage:self.shareModel.thumImage];
    //设置网页地址
    shareObject.webpageUrl = self.shareModel.webpageUrl ?  self.shareModel.webpageUrl: @"";
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
      
    }];
}


@end

@implementation ZJShareModel

- (NSString *)description{
    return [self yy_modelDescription];
}

@end








